|
|
|
|
|
|
|
If you set the peFlags field to PC_NOCOLLAPSE (4), the new color is not mapped to an existing color, even if the color is already in the system palette. Instead, the color is placed in a new system palette entry. If the system palette is full, it is mapped to the closest available color. |
|
|
|
|
|
|
|
|
If peFlags is PC_RESERVED (1), the color is mapped much as it is when peFlags is PC_NOCOLLAPSE. The color is also marked as reserved for your program's use only, so colors used by other logical palettes will not map to this entry. This is useful if you expect to change the value of the color frequently. In that case, the system might spend a lot of time remapping the colors of other applications whenever you change the value of this color. By setting peFlags to PC_RESERVED, you guarantee that other applications will not use the color, and you minimize the remapping. |
|
|
|
|
|
|
|
|
Finally, if you set peFlags to PC_EXPLICIT (2), the system maps the color directly to the corresponding system palette entry. For example, it maps the first logical palette entry to the first system palette entry. In this case, the logical palette entry always holds the value of the corresponding system palette entry. You cannot change the value of the color in the logical palette to make the system palette entry change. Instead, the logical color value changes to reflect the value of the corresponding system palette entry. |
|
|
|
|
|
|
|
|
Changing a Logical Palette While It Is in Use |
|
|
|
|
|
|
|
|
If you make a change to a logical palette while the palette is in use, you must call the function RealizePalette to make the changes take effect. This function takes as a parameter the device context of the object using the palette. The function remaps the entries in the logical palette into the system palette and returns the number of entries that were mapped to new positions. |
|
|
|
 |
|
|
|
|
Private Declare Function RealizePalette Lib "gdi32" _
Alias "RealizePalette" (ByVal hdc As Long) As Long |
|
|
|
|
|
|
|
|
The following code maps all the palette entries in the picture box picCanvas to the colors in the system palette. First, the routine resizes the control's logical palette to make it big enough to hold the entire system palette. It then fills in an array of PALETTEENTRY structures, setting the peFlags field of each to PC_EXPLICIT. It also gives each entry a different peRed value so that the colors do not all map to the same position. Finally, the routine uses SetPaletteEntries to update the logical palette. |
|
|
|
 |
|
|
|
|
' Load the Pict palette with PC_EXPLICIT entries
' so they match the system palette. Private Sub LoadSystemPalette()
Dim palentry(0 To 255) As PALETTEENTRY
Dim i As Integer
' Make the logical palette as big as possible. |
|
|
|
|
|